<?
/*
 @文件名:iMVC_Controller.php
 @类  名:iMVC_Controller
 @简  介:iMVC框架中所有controller基类,并且集成了smarty
 @版  本:1.0
 @时  间:2011年10月9日
 @作  者:Dull
 */
define('SMARTY_DIR','include/smarty_libs/');
require(SMARTY_DIR.'Smarty.class.php');
class iMVC_Controller{
    protected $template_dir='views/';
    protected $template_file='';
    protected $smarty;
    protected $get=array();
    protected $post=array();
    protected $request=array();
    protected $modelDir='models';
    function __construct(){
        //session_start();
        $this->baseUrl=substr($_SERVER['REQUEST_URI'],0,strrpos($_SERVER['PHP_SELF'],'/')+1);
        $this->before();
        $this->smarty = new Smarty;
        $this->smarty->template_dir =$this->template_dir; 
        //初始化get post
        $this->get=$_GET;
        $this->post=$_POST;
        $this->request=array_merge($this->get,$this->post);
        $this->assign("baseUrl",$this->getBaseUrl());
        set_include_path(get_include_path().PATH_SEPARATOR.$this->modelDir);
        
        //开启session

    }
    function __destruct(){
    
        $this->after(); 
    
    }
    Protected function display($file=null){
        if($file){
            $this->template_file=$file; 
        }
        $this->smarty->template_dir =$this->template_dir; 
        $this->smarty->display($this->template_file);
    }
    //设置变量值
    protected function assign($key,$value){

        $this->smarty->assign($key,$value);
    }
    //before,Controller之前执行的函数
    protected function before(){
    }
    //after,在系统释放Controller时执行的函数
    protected function after(){
    
    
    }
    public function getBaseUrl(){
        return $this->baseUrl; 
    }
    public function setViewDir($value){
        $this->template_dir=$value; 
    }
    public function setViewFile($value){
        $this->template_file=$value; 
    }


}

